<?php
if(isset($_POST['createAuth'])){
	
	if(isset($_GET['action']) && $_GET['action'] == "edit"){
		
		foreach($_POST as $key => $value){
		
			if($key == "password"){
				
				if(empty($value)){
					
					continue;
					
				}
				
			}
			
			if($key == "createAuth" || $key == "password2"){

				continue;
				
			}
			
			$uArr[$key] = $value;
			
		}
		
		if($session->updateAccount($uArr)){
			
			$success = 'updated';
			
		}else{
			
			$_SESSION['error']['usercreate'] = "Could not create new user account";
			
		}
		
	}elseif($_POST['password'] === $_POST['password2']){
		
		foreach($_POST as $key => $value){
			
			if($key == "createAuth" || $key == "password2"){

				continue;
				
			}
			
			$uArr[$key] = $value;
			
		}
		
		if($session->createAccount($uArr)){
			
			$success = 'created';
			
		}else{
			
			$_SESSION['error']['usercreate'] = "Could not create new user account";
			
		}
		
	}else{
		
		$_SESSION['error']['usercreate'] = "Passwords do not match";
		
	}
	
}

	if(isset($_GET['action']) && isset($_GET['var'])){
			
		if($_GET['action'] == "edit"){

			$uData = $session->getLPCPUser()->fetchUserData($_GET['var']);

		}

	}

	if($_GET['action'] == "edit"){
		
		print "<h3>Edit User</h3>";
		
	}else{
	
		print "<h3>Create New User</h3>";
		
	}

	if(isset($_SESSION['error']['usercreate']) && !empty($_SESSION['error']['usercreate'])){
		
		print "<i id='error'>".$_SESSION['error']['usercreate']."</i>";
		unset($_SESSION['error']);
		
	}
	
	if($success){
		print "<i id='success'>Successfully ".$success." user account!</i>";
		unset($success);
		
	}
?>